package Service;

import Dao.Impl.PetDaoImpl;
import Dao.Impl.PetStoreImpl;
import Entity.pet;
import Entity.pet_owner;
import Entity.pet_store;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class PetStoreServiceImpl implements  PetStoreService {

    PetStoreImpl petStore =new PetStoreImpl();
    PetDaoImpl petDao =new PetDaoImpl();
    @Override
    public void GetAllPetStore() throws SQLException {

        List<pet_store> p =petStore.AllGetPetStore();
        for(pet_store pp:p)
        {
            System.out.println("第"+pp.getId()+"个宠物商店，名字是："+pp.getName());
        }
    }

    @Override
    public int login() throws SQLException {
        System.out.println("请先登陆");
        System.out.println("请输入宠物商店的名字");
        Scanner scanner = new Scanner(System.in);
        String name= scanner.nextLine();
        System.out.println("请输入此账号的密码");
        String password= scanner.nextLine();
        pet_store pet_store= petStore.Login(name,password);
        if(pet_store!=null)
        {
            System.out.println("************登陆成功**************");
            System.out.println("************您的基本信息**************");
            System.out.println("名字:"+pet_store.getName());
            System.out.println("元宝数:"+String.valueOf( pet_store.getBalance()));

        }
        else{
            System.out.println("************账号密码错误，登陆失败**************");
        }
        return pet_store.getId();

    }

    @Override
    public int find(int store_id) throws SQLException {
        List<pet_store> p =petStore.AllGetPetStore();
        return p.get(store_id-1).getId();
    }

    @Override
    public List<pet> AllPetBystore(int id) throws SQLException {
        List<pet> pets=petDao.AllPetBystore(id);
        return pets;
    }
}
